//
//  WodejifenViewController.m
//  tianjin
//
//  Created by 鞠超 on 16/8/11.
//  Copyright © 2016年 jc. All rights reserved.
//

#import "WodejifenViewController.h"

#import "WodejifenTableViewCell.h"

@interface WodejifenViewController () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView * tableView;
//头视图
@property (nonatomic, strong) UIView * view_headBg;
//
@property (nonatomic, strong) UILabel * jifen;

@end

@implementation WodejifenViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self p_navi];
    
    [self p_setupView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - navi
- (void)p_navi
{
    _btnLeft.hidden = YES;
    _lblLeft.hidden = YES;
    _btnRight.hidden = YES;
    _lblRight.hidden = YES;
    _topView.backgroundColor = [UIColor blackColor];
    
    _lblTitle.text = @"我的积分";
    _lblTitle.textColor = [UIColor whiteColor];
    _lblTitle.font = [UIFont systemFontOfSize:19];
    
    UIImageView * image_return = [[UIImageView alloc] initWithFrame:CGRectMake(15, 32, 10, 20)];
    image_return.image = [UIImage imageNamed:@"zuofanhui@2x.png"];
    [_topView addSubview:image_return];
    
    UIButton * btn_return = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_return.frame = CGRectMake(10, 20, 35, 44);
    [_topView addSubview:btn_return];
    [btn_return addTarget:self action:@selector(btn_returnAction:) forControlEvents:(UIControlEventTouchUpInside)];
}

//左返回
- (void )btn_returnAction:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

//显示tabbar
- (void )viewWillAppear:(BOOL)animated
{
    [(AppDelegate *)[[UIApplication sharedApplication] delegate] hiddenTabBar];
}

#pragma mark - 布局
- (void )p_setupView
{
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64) style:(UITableViewStylePlain)];
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.tableFooterView = [[UIView alloc] init];
    [self.view addSubview:self.tableView];
    
    //注册
    [self.tableView registerClass:[WodejifenTableViewCell class] forCellReuseIdentifier:@"cell_jifen"];
}

#pragma mark - tableview代理
- (NSInteger )numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}

- (CGFloat )tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    WodejifenTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell_jifen" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    //判断+.—来改变颜色
    cell.jifen.textColor = navi_bar_bg_color;
    
    return cell;
}

//头视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    [self p_headView];

    return self.view_headBg;
}

- (CGFloat )tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 150;
}

#pragma mark - 点击升级会员
- (void )btn_huiyuanAction:(UIButton *)sender
{
    NSLog(@"点击升级会员");
}

#pragma mark - 头视图
- (void )p_headView
{
    self.view_headBg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 150)];
    self.view_headBg.backgroundColor = [UIColor whiteColor];
    
    UIImageView * image_bg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 100)];
    image_bg.image = [UIImage imageNamed:@"jifen_bg@2x.png"];
    image_bg.userInteractionEnabled = YES;
    [self.view_headBg addSubview:image_bg];
    
    UILabel * lbl_1 = [[UILabel alloc] initWithFrame:CGRectMake(25, 20, 100, 20)];
    lbl_1.text = @"我的积分";
    lbl_1.textColor = [UIColor whiteColor];
    lbl_1.font = [UIFont systemFontOfSize:18];
    [image_bg addSubview:lbl_1];
    
    self.jifen = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMinX(lbl_1.frame), CGRectGetMaxY(lbl_1.frame) + 20, (SCREEN_WIDTH - 50) / 2, 20)];
    self.jifen.textColor = [UIColor redColor];
    self.jifen.font = [UIFont systemFontOfSize:18];
    self.jifen.text = @"10000";
    [image_bg addSubview:self.jifen];
    
    UIButton * btn_huiyuan = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_huiyuan.frame = CGRectMake(SCREEN_WIDTH - 30 - 85, 35, 85, 30);
    btn_huiyuan.layer.cornerRadius = 5;
    btn_huiyuan.layer.borderColor = [UIColor whiteColor].CGColor;
    btn_huiyuan.layer.borderWidth = 1;
    [btn_huiyuan setTitle:@"升级会员" forState:(UIControlStateNormal)];
    [btn_huiyuan setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    [image_bg addSubview:btn_huiyuan];
    [btn_huiyuan addTarget:self action:@selector(btn_huiyuanAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    //
    UILabel * jifen_detail = [[UILabel alloc] initWithFrame:CGRectMake(10, 100 + 15, 100, 20)];
    jifen_detail.text = @"积分详情";
    jifen_detail.textColor = [UIColor grayColor];
    jifen_detail.font = [UIFont systemFontOfSize:17];
    [self.view_headBg addSubview:jifen_detail];
    
    UIView * view_1 = [[UIView alloc] initWithFrame:CGRectMake(0, 149, SCREEN_WIDTH, 1)];
    view_1.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.view_headBg addSubview:view_1];
}














@end
